package main

import (
	"fmt"
	"time"
)

func main() {
	chA := make(chan struct{})
	chD := make(chan struct{})
	chC := make(chan struct{})

	go printApple(chA, chC)
	go printDog(chD, chC)
	go printCat(chC, chA)

	chA <- struct{}{}

	time.Sleep(10 * time.Second)
}

func printCat(chC, chD chan struct{}) {
	for i := 0; i < 100; i++ {
		<-chC
		fmt.Println("printCat is printing: ", i)
		chD <- struct{}{}
	}
}

func printDog(chD, chA chan struct{}) {
	for i := 0; i < 100; i++ {
		<-chD
		fmt.Println("printDog is printing: ", i)
		chA <- struct{}{}
	}
}

func printApple(chA, chC chan struct{}) {
	for i := 0; i < 100; i++ {
		<-chA
		fmt.Println("printApple is printing: ", i)
		chC <- struct{}{}
	}
}
